package org.yiqixue.accounts.repository;

import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.yiqixue.accounts.entity.Accounts; // 确保这是实体类的正确导入

import java.util.Optional;

@Repository
public interface AccountsRepository extends JpaRepository<Accounts, Long> {

    // 通过客户ID查询账户
    Optional<Accounts> findByCustomerId(Long customerId);

    // 通过手机号查找账户
    Optional<Accounts> findByPhoneNumber(String phoneNumber);  // 新增通过手机号查找账户的方法

    @Transactional
    @Modifying
    void deleteByCustomerId(Long customerId);
}
